package spring.yongongsystem.controller.admin;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import spring.yongongsystem.POJO.dto.GroupPageQueryDTO;
import spring.yongongsystem.POJO.dto.MerchantDTO;
import spring.yongongsystem.POJO.dto.MerchantPageQueryDTO;
import spring.yongongsystem.POJO.entity.Group;
import spring.yongongsystem.result.PageResult;
import spring.yongongsystem.result.Result;
import spring.yongongsystem.service.GroupService;
@CrossOrigin(origins = "http://localhost:5173")
@RestController("adminGroupController")
@RequestMapping("/admin/group")
@Api(tags = "管理员小组相关接口")
@Slf4j
public class GroupController {

    @Autowired
    private GroupService groupService;

    /**
     * 新增小组
     * @param group
     * @return
     */
    @PostMapping
    @ApiOperation("新增小组")
    public Result save(@RequestBody Group group){
        log.info("新增小组：{}",group);
        groupService.save(group);
        return Result.success();
    }

    /**
     * 小组分页查询
     * @param groupPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("小组分页查询")
    public Result<PageResult> page(GroupPageQueryDTO groupPageQueryDTO){
        log.info("小组分页查询，参数为：{}", groupPageQueryDTO);
        PageResult pageResult = groupService.pageQuery(groupPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除小组
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除小组")
    public Result<String> deleteById(Long id){
        log.info("删除小组：{}", id);
        groupService.deleteById(id);
        return Result.success();
    }

    /**
     * 编辑小组信息
     * @param group
     * @return
     */
    @PutMapping
    @ApiOperation("编辑小组信息")
    public Result update(@RequestBody Group group){
        log.info("编辑小组信息：{}", group);
        groupService.update(group);
        return Result.success();
    }
}
